package com.gy.zpchat.ui.meeting.adapter;

import android.view.ViewGroup;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class InMeetingAdapter extends RecyclerView.Adapter<InMeetingUserHolder> {
    private final ArrayList<CallData> inMeetingDataList = new ArrayList<>();
    private String callerID = "";
    public ArrayList<CallData> chooseData = new ArrayList<>();
    @NonNull
    @Override
    public InMeetingUserHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new InMeetingUserHolder(parent);
    }

    @Override
    public void onBindViewHolder(@NonNull InMeetingUserHolder holder, int position) {

        CallData data = inMeetingDataList.get(position);
        holder.setData(data,callerID);
        holder.getChooseView().setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    chooseData.add(data);
                }else {
                    chooseData.remove(data);
                }
            }
        });
    }

    public void setDataAndNotify(ArrayList<CallData> data){
        inMeetingDataList.clear();
        inMeetingDataList.addAll(data);

        notifyDataSetChanged();
    }

    public void setCallerID(String callerID){
        this.callerID = callerID;
    }
    @Override
    public int getItemCount() {
        return inMeetingDataList.size();
    }
}
